package com.gui.service;

import com.gui.exception.DIYExceptionHandler;
import com.gui.mapper.UserMapper;
import com.gui.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * LoginService
 *
 * @author guigu
 * @QQ 1170258867
 * @date 2020/5/27
 * @description gitee第三方登录操作
 */
@Service
public class LoginService {

    @Autowired
    private UserMapper usermapper;

    /***
     * @param user
     * 持久化到H2,每次的令牌token必须更新
     */
    public void saveOrUpdate(User user) throws DIYExceptionHandler {
        String s = usermapper.selectName(user.getAccountId());
        if (s==null){
            usermapper.insert(user);
        }else{
            int update = usermapper.update(user);
            if (update==0){
                throw new DIYExceptionHandler("登录异常");
            }
        }
    }
}
